import os
from pathlib import Path

def create_file(file_path, content):
    """Create a file with the given content"""
    os.makedirs(os.path.dirname(file_path), exist_ok=True)
    with open(file_path, 'w', encoding='utf-8') as f:
        f.write(content)

def create_missing_drawables(project_root):
    """Create all missing drawable resources"""
    res_dir = os.path.join(project_root, 'app', 'src', 'main', 'res')
    drawable_dir = os.path.join(res_dir, 'drawable')
    
    # Create ic_add.xml
    ic_add_content = """<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24"
        android:viewportHeight="24"
        android:tint="?attr/colorControlNormal">
        <path
            android:fillColor="@android:color/white"
            android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
    </vector>"""
    create_file(os.path.join(drawable_dir, 'ic_add.xml'), ic_add_content)
    
    # Create ic_edit.xml
    ic_edit_content = """<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24"
        android:viewportHeight="24"
        android:tint="?attr/colorControlNormal">
        <path
            android:fillColor="@android:color/white"
            android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83l3.75,3.75l1.83,-1.83z"/>
    </vector>"""
    create_file(os.path.join(drawable_dir, 'ic_edit.xml'), ic_edit_content)
    
    # Create ic_delete.xml
    ic_delete_content = """<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24"
        android:viewportHeight="24"
        android:tint="?attr/colorControlNormal">
        <path
            android:fillColor="@android:color/white"
            android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6V19zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
    </vector>"""
    create_file(os.path.join(drawable_dir, 'ic_delete.xml'), ic_delete_content)
    
    print("✅ Successfully created all missing drawable resources!")

if __name__ == "__main__":
    # Get the project root directory (where this script is located)
    project_root = input("Enter the path to your Android project root directory: ").strip()
    
    # Validate path
    if not os.path.isdir(project_root):
        print(f"Error: The path '{project_root}' is not a valid directory.")
    elif not os.path.exists(os.path.join(project_root, 'app', 'src', 'main')):
        print("Error: This doesn't appear to be an Android project directory.")
        print("Please provide the root directory of your Android project (contains app/, gradle/, etc.)")
    else:
        create_missing_drawables(project_root)
        print("\nNext steps in Android Studio:")
        print("1. Go to Build -> Clean Project")
        print("2. Then Build -> Rebuild Project")
        print("3. If issues persist, File -> Invalidate Caches / Restart")